//
//  LKChartsListViewController.m
//  YLHelper
//
//  Created by she1323 on 2018/5/22.
//  Copyright © 2018年 she1323. All rights reserved.
//

#import "LKChartsListViewController.h"
#import "LKChartDateCell.h"
#import "LKChartListDefaultCell.h"
#import "LKInstrumentBoardView.h"
#import "LKDoubuleBarView.h"
#import "LKRadarView.h"
#import "LKLineView.h"
#import "LKPieView.h"
#import "LKChartsListRankDetailViewController.h"
@interface LKChartsListViewController ()<UITableViewDelegate,UITableViewDataSource>
@property(nonatomic,strong)LKBaseTableview *tableview;
@property(nonatomic,strong)NSArray *headerTitlesArray;
@property(nonatomic,strong)UIView *headerView;
@property(nonatomic,strong)UILabel *headerLabel;
@property(nonatomic,strong)UIView *footerView;
@end

@implementation LKChartsListViewController
-(LKBaseTableview *)tableview{
    if (!_tableview) {
        _tableview = [LKBaseTableview setTableviewWithFrame:CGRectMake(0, 12 + NAVIGATION_BAR_HEIGHT, WIDTH, HEIGHT - 12 - NAVIGATION_BAR_HEIGHT) style:UITableViewStyleGrouped registercellClasss:@[@"LKChartDateCell",@"LKChartListDefaultCell"]];
        [self.view addSubview:_tableview];
        _tableview.delegate = self;
        _tableview.dataSource = self;
        _tableview.separatorStyle = UITableViewCellSelectionStyleGray;
        _tableview.tableFooterView = [[UIView alloc] init];
        _tableview.backgroundColor = cellHeaderBgColor;
    }
    return _tableview;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.tableview.estimatedRowHeight = 200;
    // Do any additional setup after loading the view.
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return self.headerTitlesArray.count;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 1;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    switch (indexPath.section) {
        case 0:
        {
            LKChartListDefaultCell *cell = [tableView dequeueReusableCellWithIdentifier:@"LKChartListDefaultCell"];
            for (UIView * view in cell.chartBgView.subviews) {
                
                [view removeFromSuperview];
                
            }
            LKDoubuleBarView *view = [LKDoubuleBarView creteDoubleViewWithFrame:CGRectMake(0, 0, WIDTH - 46, 320) andLineValues:@[@[@"2.24", @"16.79", @"14.54", @"2.25", @"23"],@[@"9.29", @"7.79", @"4.54", @"12.25", @"3"],@[@"-6.24", @"6.79", @"6.54", @"9.25", @"-3"]] andBarValues:@[@[@"23.8", @"27.46", @"31.13", @"40.68", @"28.85"],@[@"23.8", @"27.46", @"31.13", @"20.68", @"28.85"]] andXvalue:@[@"2012-05",@"2012-06",@"2012-07",@"2012-08",@"2012-09"] AndShowRightAxis:YES AndLinesClors:@[COLOR_HEX(0x98E3E4),COLOR_HEX(0xCCBEE8),COLOR_HEX(0x5F80D1)] AndBarColors:@[COLOR_HEX(0x98E3E4),COLOR_HEX(0xCCBEE8)] AndLineNames:@[@"规模业绩",@"年化业绩",@"折标率"] AndBarNames:@[@"业绩同比",@"业绩环比"]];
            [cell.chartBgView addSubview:view];
            [[cell.seeRankBtn rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
                LKChartsListRankDetailViewController *vc = [[LKChartsListRankDetailViewController alloc] init];
                [self.navigationController pushViewController:vc animated:YES];
            }];
            return cell;
        }
            break;
        case 1:
        {
            LKChartListDefaultCell *cell = [tableView dequeueReusableCellWithIdentifier:@"LKChartListDefaultCell"];
            for (UIView * view in cell.chartBgView.subviews) {
                
                [view removeFromSuperview];
                
            }
            LKDoubuleBarView *view = [LKDoubuleBarView creteDoubleViewWithFrame:CGRectMake(0, 0, WIDTH - 46, 320) andLineValues:@[@[@"2.24", @"16.79", @"14.54", @"2.25", @"23"],@[@"9.29", @"7.79", @"4.54", @"12.25", @"3"]] andBarValues:@[@[@"23.8", @"27.46", @"31.13", @"40.68", @"28.85"]] andXvalue:@[@"2012-05",@"2012-06",@"2012-07",@"2012-08",@"2012-09"] AndShowRightAxis:YES AndLinesClors:@[COLOR_HEX(0x98E3E4),COLOR_HEX(0xCCBEE8)] AndBarColors:@[COLOR_HEX(0x98E3E4)] AndLineNames:@[@"新客增长同比",@"新客增长环比"] AndBarNames:@[@"新客增长数量"]];
            [cell.chartBgView addSubview:view];
            return cell;
        }
            break;
        case 2:
        {
            LKChartDateCell *cell = [tableView dequeueReusableCellWithIdentifier:@"LKChartDateCell"];
            for (UIView * view in cell.chartBgView.subviews) {
                
                [view removeFromSuperview];
                
            }
                LKInstrumentBoardView *view = [[LKInstrumentBoardView alloc] initWithFrame:CGRectMake(0, 38, WIDTH - 46, 200)];
                view.processLabel.text = @"62.71%";
                [view progress:56];
                [cell.chartBgView addSubview:view];
            return cell;
        }
            break;
        case 3:
        {
            LKChartListDefaultCell *cell = [tableView dequeueReusableCellWithIdentifier:@"LKChartListDefaultCell"];
            for (UIView * view in cell.chartBgView.subviews) {

                [view removeFromSuperview];

            }
            LKLineView *lineView = [LKLineView createLineViewWithFrame:CGRectMake(0, 10, WIDTH - 46, 320)  AndLineValues:@[@[@"2.24", @"16.79", @"14.54", @"2.25", @"23"],@[@"9.29", @"7.79", @"4.54", @"12.25", @"3"],@[@"7",@"9",@"8",@"6",@"18"]] AndXValue:@[@"2012-05",@"2012-06",@"2012-07",@"2012-08",@"2012-09"] AndShowShowRightAxis:NO AndLinesClors:@[COLOR_HEX(0x98E3E4),COLOR_HEX(0xCCBEE8),[UIColor cyanColor]] AndLineNames:@[@"续投率",@"续投率同比",@"续投率环比"] AndDrawFillCorlor:@[[UIColor clearColor],[UIColor clearColor],[UIColor clearColor]]];
            [cell.chartBgView addSubview:lineView];
            return cell;
        }
            break;
        case 4:
        {
            LKChartListDefaultCell *cell = [tableView dequeueReusableCellWithIdentifier:@"LKChartListDefaultCell"];
            for (UIView * view in cell.chartBgView.subviews) {
                
                [view removeFromSuperview];
            }
            LKDoubuleBarView *view = [LKDoubuleBarView creteDoubleViewWithFrame:CGRectMake(0, 0, WIDTH - 46, 320) andLineValues:@[@[@"2.24", @"16.79", @"14.54", @"2.25", @"23"],@[@"9.29", @"7.79", @"4.54", @"12.25", @"3"]] andBarValues:@[@[@"23.8", @"27.46", @"31.13", @"40.68", @"28.85"]] andXvalue:@[@"2012-05",@"2012-06",@"2012-07",@"2012-08",@"2012-09"] AndShowRightAxis:YES AndLinesClors:@[COLOR_HEX(0x98E3E4),COLOR_HEX(0xCCBEE8)] AndBarColors:@[COLOR_HEX(0x98E3E4)] AndLineNames:@[@"人均产能同比",@"人均产能环比"] AndBarNames:@[@"人均产能"]];
            [cell.chartBgView addSubview:view];
            return cell;
        }
            break;
        case 5:
        {
            LKChartListDefaultCell *cell = [tableView dequeueReusableCellWithIdentifier:@"LKChartListDefaultCell"];
            for (UIView * view in cell.chartBgView.subviews) {
                [view removeFromSuperview];
                
            }
            LKLineView *lineView = [LKLineView createLineViewWithFrame:CGRectMake(0, 10, WIDTH - 46, 320)  AndLineValues:@[@[@"2.24", @"16.79", @"14.54", @"2.25", @"23"]] AndXValue:@[@"2012-05",@"2012-06",@"2012-07",@"2012-08",@"2012-09"] AndShowShowRightAxis:NO AndLinesClors:@[COLOR_HEX(0x98E3E4)] AndLineNames:@[@"L"] AndDrawFillCorlor:@[[UIColor redColor]]];
            [cell.chartBgView addSubview:lineView];
            return cell;
        }
            break;
        case 6:
        {
            LKChartDateCell *cell = [tableView dequeueReusableCellWithIdentifier:@"LKChartDateCell"];
            for (UIView * view in cell.chartBgView.subviews) {
                
                [view removeFromSuperview];
                
            }
            LKPieView *view = [LKPieView createPieViewWithFrame:CGRectMake(0, 10, WIDTH - 46, 220) AndValues:@[@21,@28,@20,@12,@19] AndColors:@[[UIColor redColor],[UIColor yellowColor],[UIColor greenColor],[UIColor purpleColor],[UIColor cyanColor]] AndPieNames:@[@"游客",@"普通会员",@"VIP会员",@"SVIP会员",@"尊享会员"]];
            [cell.chartBgView addSubview:view];
            return cell;
        }
            break;
        case 7:
        {
            LKChartDateCell *cell = [tableView dequeueReusableCellWithIdentifier:@"LKChartDateCell"];
            for (UIView * view in cell.chartBgView.subviews) {
                
                [view removeFromSuperview];
                
            }
            LKInstrumentBoardView *view = [[LKInstrumentBoardView alloc] initWithFrame:CGRectMake(0, 0, WIDTH - 46, 300)];
            view.processLabel.text = @"62.71%";
            [view progress:56];
            [cell.chartBgView addSubview:view];
            return cell;
        }
            break;
        default:
            break;
    }
    return [tableView cellForRowAtIndexPath:indexPath];
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
//    switch (indexPath.section) {
//        case 0:
//            {
//                return 415;
//            }
//            break;
//        case 1:
//        {
//            return 415;
//        }
//            break;
//        case 2:
//        {
//            return 300;
//        }
//            break;
//        case 3:
//        {
//            return 415;
//        }
//            break;
//        case 4:
//        {
//            return 415;
//        }
//            break;
//        case 5:
//        {
//            return 415;
//        }
//            break;
//        case 6:
//        {
//            return 300;
//        }
//            break;
//        case 7:
//        {
//            return 415;
//        }
//            break;
//        default:
//            break;
//    }
    return 415;
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView * headerView = [[UIView alloc] init];
    headerView.backgroundColor = [UIColor whiteColor];
    UILabel * headerLabel = [[UILabel alloc] init];
    headerLabel.textAlignment = NSTextAlignmentCenter;
    [headerView addSubview:headerLabel];
    [headerLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(headerView);
    }];
    headerLabel.text = self.headerTitlesArray[section];
    return headerView;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 50;
}
-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    return self.footerView;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 12;
}
//-(UIView *)headerView{
//    if (!_headerView) {
//        _headerView = [[UIView alloc] init];
//        _headerView.backgroundColor = [UIColor whiteColor];
//        self.headerLabel = [[UILabel alloc] init];
//        self.headerLabel.textAlignment = NSTextAlignmentCenter;
//        [_headerView addSubview:self.headerLabel];
//        [self.headerLabel mas_makeConstraints:^(MASConstraintMaker *make) {
//            make.center.equalTo(_headerView);
//        }];
//
//    }
//    return _headerView;
//}
-(UIView *)footerView{
    if (!_footerView) {
        _footerView = [[UIView alloc] init];
        _footerView.backgroundColor = cellHeaderBgColor;
    }
    return _footerView;
}
-(NSArray *)headerTitlesArray{
    if (!_headerTitlesArray) {
        _headerTitlesArray = @[@"业绩",@"新客增长",@"达成率",@"续投率",@"人均产能",@"业绩-规模贡献率",@"客户-等级构成",@"构成-产品"];
    }
    return _headerTitlesArray;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
